//
//  XJWalletTiXianAccountViewController.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/23.
//  Copyright © 2018年 Tzyang. All rights reserved.
//  提现账户。

//controller
#import "XJWalletTiXianAccountViewController.h"
#import "XJWalletAddZFBAccountViewController.h"
#import "XJWalletAddBankAccountViewController.h"

//view
#import "XJWalletZFBView.h"
#import "XJWalletBankView.h"

//model
#import "XJWalletTiXianBankModel.h"


@interface XJWalletTiXianAccountViewController ()
@property(nonatomic, strong)XJWalletZFBView *zfbView;
@property(nonatomic, strong)XJWalletBankView *bankView;



@end

@implementation XJWalletTiXianAccountViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupView];
    
    self.navigationItem.title = @"提现账户";
    
    [self requestData];
}

- (void)setupView {
    [self.view addSubview:self.zfbView];
    
    [self.view addSubview:self.bankView];
}

- (XJWalletZFBView *)zfbView {
    if (!_zfbView) {
        _zfbView = [[XJWalletZFBView alloc] initWithFrame:CGRectMake(0, 0, KWidth, 80)];

        
        XJWeakSelf(self);
        XJWalletAddZFBAccountViewController *addZFBVC = [[XJWalletAddZFBAccountViewController alloc] init];
        
        _zfbView.editButtonBlock = ^{
            [weakself.navigationController pushViewController:addZFBVC animated:YES];

        };
        _zfbView.tapNodataIvBlock = ^{
            [weakself.navigationController pushViewController:addZFBVC animated:YES];
        };
    }
    return _zfbView;
}

- (XJWalletBankView *)bankView {
    if (!_bankView) {
        _bankView = [[XJWalletBankView alloc] initWithFrame:CGRectMake(0, 120, KWidth, 80)];

        XJWalletAddBankAccountViewController *addBankVC = [[XJWalletAddBankAccountViewController alloc] init];
        
        XJWeakSelf(self);
        _bankView.editButtonBlock = ^{
            [weakself.navigationController pushViewController:addBankVC animated:YES];
        };
        _bankView.noDataIvClickBlock = ^{
            [weakself.navigationController pushViewController:addBankVC animated:YES];
        };
    }
    return _bankView;
}

#pragma mark - 手势

#pragma mark - 三 请求数据
- (void)requestData {
    [XJHttpTool requestCustomAccountAccountListSuccessH:^(id responseObjc) {
        
        NSString *code = [NSString stringWithFormat:@"%@",responseObjc[@"code"]];
        if ([code isEqualToString:@"0"]) {
            NSArray *account_list = responseObjc[@"data"][@"account_list"];
            
            //是怎么写出这样的垃圾代码的的？
            //服务器返回一个数组(两个model还不一样) 每次的顺序也不一样。dic在数组中的位置也不一样。我又想转模型。我需要的只是将对应的dic转换为对应的model 。我能想到的是:判断dic中是否有对应的key 来找到对应的dic--->model 
            
            for (NSDictionary * tempDic in account_list) {

                NSArray *allkeys = [tempDic allKeys];
                if ([allkeys containsObject:@"bank_branch"]) {
                    //两个模型不一样
                    XJWalletTiXianBankModel *bankM = [XJWalletTiXianBankModel mj_objectWithKeyValues:tempDic];
                    self.bankView.bankModel = bankM;
                }else {
                    XJWalletTiXianZFBModel *zfbM = [XJWalletTiXianZFBModel mj_objectWithKeyValues:tempDic];
                    self.zfbView.zfbModel = zfbM;
                }
            }
        }
    } failH:^(NSError *error) {
        [JRToast showWithText:[error localizedDescription]];
    }];
}

#pragma mark - 四 业务逻辑
/**
服务器没有返回数据的 时候 显示的界面
 
 有数据的时候的界面
 背景变为彩色的 添加银行卡、添加支付宝账号文字消失。编辑按钮可点。背景图片不可点。
 
 没有数据的时候的界面。
 背景灰色的 文字显示为 添加银行卡 、 添加支付宝账号
 背景可以点击
 
 */
@end
